package ua.edu.nuos.jeetraining2012.cms.util.svn;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: artur
 * Date: 28.06.13
 * Time: 13:56
 * To change this template use File | Settings | File Templates.
 */
public class RepositoryProperties {
    static private Properties prop = new Properties();

    public static void loadProperties() {
        try {
            prop.load(RepositoryProperties.class.getClassLoader().getResourceAsStream("svn/svn.properties"));
        } catch (IOException e) {
            System.out.println(e.getMessage());
        };
    }

    public static String getPath(){
        loadProperties();
        return prop.getProperty("path");
    }

    public static Map<String, String> getAdmin(){
        loadProperties();

        Map<String, String> admin = new HashMap<>();
        admin.put("name", "admin");
        admin.put("passwd",prop.getProperty("admin"));
        return admin;
    }

    public static String getServerUrl() {
        loadProperties();
        String host = (prop.get("host") != null && !prop.getProperty("host").isEmpty())
                ? String.valueOf(prop.get("host"))
                : "localhost";
        String port = (prop.get("port") != null && !prop.getProperty("port").isEmpty())
                ? ":" + String.valueOf(prop.get("port"))
                : "";
        return host + ":" + port + "/";
    }
}
